package org.csu.demo.aop.test;

import org.csu.demo.aop.persistence.AccountDAO;
import org.csu.demo.aop.persistence.AccountDAOImpl;
import org.csu.demo.aop.proxy.ProxyDemo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.lang.reflect.Proxy;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext-aop.xml")
public class Demo {
    @Autowired
    private AccountDAO accountDAO;

    @Test
    public void test(){

    accountDAO.insert();
//        AccountDAO accountDAO = new AccountDAOImpl();
//
//        //获取类的原型
//        Class class1 = accountDAO.getClass();
//        //生成一个代理对象
//        Object object = Proxy.newProxyInstance(class1.getClassLoader(),class1.getInterfaces(),new ProxyDemo(accountDAO));
//        accountDAO = (AccountDAO) object;
//        accountDAO.insert();
//        accountDAO.update();
    }
}
